from Autotests.LocalMachine.Controls.Button import WebButton
from Autotests.LocalMachine.Controls.LineEdit import WebLineEdit
from Autotests.LocalMachine.Controls.CheckBox import WebDefaultCheckBox
from Autotests.LocalMachine.Controls.ComboBox import WebComboBox
from Autotests.LocalMachine.UiObjectsMap.AirClient import Options
from Autotests.LocalMachine.Pages.BaseDialog import BaseWebTreeDialog
from OptionsPage import OptionsPage
import time

class SpeedKickType(object):
    local = "local"
    network = "network"


class LocalSpeedKickTab(OptionsPage):
    def __init__(self):
        super(LocalSpeedKickTab, self).__init__()
        self._checkBoxCacheEnabled = WebDefaultCheckBox(Options.LocalSpeedKick.checkboxBackupCacheEnabled)
        self._comboBoxDriveType = WebComboBox(Options.LocalSpeedKick.comboBoxDriveType)
        self._textBoxLocation = WebLineEdit(Options.LocalSpeedKick.txtBoxCacheLocation)
        self._textBoxUser = WebLineEdit(Options.LocalSpeedKick.txtBoxUser)
        self._textBoxPassword = WebLineEdit(Options.LocalSpeedKick.txtBoxPassword)
        self._treeLocation = BaseWebTreeDialog()

    def goToHomeLocation(self):
        super(LocalSpeedKickTab, self).goToHomeLocation()
        WebButton(Options.btnLocalSpeedKick).click()

    @OptionsPage.setter
    def enableLskLocalSettings(self, path, speedKickType=SpeedKickType.local):
        self._checkBoxCacheEnabled.setCheckState(True)
        self._comboBoxDriveType.selectItemsByDataValue(speedKickType)
        self._textBoxLocation.click()
        time.sleep(1)
        self._treeLocation.setItemSelection(path)

    @OptionsPage.getter
    def getLskSettings(self):
        driveType = None
        lskPath = None
        lskUser = None
        lskPassword = None
        isEnabled = self._checkBoxCacheEnabled.isChecked()
        if isEnabled:
            driveType = self._comboBoxDriveType.currentItem().dataValue()
            lskPath = self._textBoxLocation.text()
            if driveType == SpeedKickType.network:
                lskUser = self._textBoxUser.text()
                lskPassword = self._textBoxPassword.text()
        return isEnabled, driveType, lskPath, lskUser, lskPassword

    @OptionsPage.setter
    def disableLskSettings(self):
        self._checkBoxCacheEnabled.setCheckState(False)


